<?php

namespace App\Model;


use Illuminate\Http\Request;

class FriendsReport extends BaseModel
{
    protected $table = 'friends_report';
    public $timestamps = false;
    private $fields = ['*'];
    
    public function getPicsAttribute($value){
        $value = json_decode($value,true);
        if(!empty($value)){
            return $value[0];
        }
        return '';
    }
    
    public function getList(Request $request){
        $limit = $request->input('limit',10);
        $page = $request->input('page', 1);
        $dispose = $request->input('dispose');
        $uuid = $request->input('uuid','');
    
        $query = new FriendsReport();
        
        if($dispose) $query = $query->where(['dispose' => $dispose]);
        
        return $query->orderBy('id','DESC')->whereHas('reportUser',function ($query) use ($uuid){
            if($uuid) $query->where('uuid', $uuid);
        })->with(['reportUser','byReportUser'])->paginate($limit,$this->fields,'page',$page);
    }
    public function reportUser(){
        return $this->belongsTo(Number::class,'user_id','user_id');
    }
    
    public function byReportUser(){
        return $this->belongsTo(Number::class,'report_user_id','user_id');
    }


    //更新
    public function updateData($data)
    {
        return curl_request(getKkaudioApiUrl() . '/inner/friends/report/update', $data, 'urlencoded', 'GET');
    }




}
